#ifndef CGAMECLASS_H_
#define CGAMECLASS_H_
#include <vector>
#include <stack>
#include "CTimer.h"
#include "CMessageSystem.h"
#include "CEventSystem.h"
#include "MMath.h"
#include "CBaseGameState.h"
#include "CBase.h"

using namespace std;

// forward declarations
//class DXDeviceControl;
class CSGD_DirectInput;

class CGameClass
{
private:

	CTimer						*m_pTimer;
	CMessenger					*m_pMessenger;
	CDispatcher					*m_pDispatcher;
	stack<CBaseGameState *>		m_StateStack;
	HINSTANCE*					m_pHINSTANCE;
	HWND*						m_pHWND;

	// Our D3D9 Device
	//DXDeviceControl*			m_devControl;
	// DirectInput
	CSGD_DirectInput*			m_pDI;

	int							m_nScreenWidth;
	int							m_nScreenHeight;

	CGameClass() { }
	CGameClass(CGameClass &) { }
	CGameClass &operator=(CGameClass &) { }


	// helper functions
	//void InitDX();B

	//void OnResetDevice(void);
	//void OnLostDevice(void);

	void Update(void);
	void Render(void);
	void Input(void);

public:
	bool						m_bIsRunning;

	~CGameClass() { }

	static CGameClass *GetInstance()
	{
		static CGameClass Instance;
		return &Instance;
	}

	void Init(HWND* _pHWND, HINSTANCE *_pHINSTANCE, int _width, int _height);

	bool GameLoop();

	void Shutdown();

	// Accessors
	inline int GetScreenWidth(void) const {return m_nScreenWidth;}
	inline int GetScreenHeight(void) const {return m_nScreenHeight;}

	//State machine
	void ClearStateStack();
	void ChangeState(CBaseGameState *pState);
	void PushState(CBaseGameState *pState);
	void PopState();

	friend void MsgProc(string szID, void *pSender, void *pArgs);
};

#endif